#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

import os
import os.path
from tools.scons.RunTest import run_test

Import('test_env')

# SConscript file for Local PKI google tests
stacktest_env = test_env.Clone()
target_os = stacktest_env.get('TARGET_OS')
rd_mode = stacktest_env.get('RD_MODE')

######################################################################
# Build flags
######################################################################
stacktest_env.PrependUnique(CPPPATH=[
    '../../security/include',
    '../../ocsocket/include',
    '../../logger/include',
    '../../../c_common/ocrandom/include',
    '../../include',
    '../../stack/include',
    '../../stack/include/internal',
    '../../connectivity/api',
    '../../connectivity/inc/pkix',
    '../../connectivity/external/inc',
    '../../../oc_logger/include',
    '#resource/csdk/connectivity/inc',
    '#resource/csdk/connectivity/lib/libcoap-4.1.1/include',
    '#resource/csdk/connectivity/common/inc',
])

stacktest_env.PrependUnique(LIBS=[
    'octbstack_internal',
    'ocsrm',
    'routingmanager',
    'connectivity_abstraction_internal',
    'coap',
])

if stacktest_env.get('SECURED') == '1':
    stacktest_env.AppendUnique(LIBS=['mbedtls', 'mbedx509'])

# c_common calls into mbedcrypto.
stacktest_env.AppendUnique(LIBS=['mbedcrypto'])

if 'CLIENT' in rd_mode and target_os not in ['darwin', 'ios', 'windows', 'winrt']:
    stacktest_env.PrependUnique(LIBS=['oc', 'oc_logger'])
if 'SERVER' in rd_mode:
    if target_os in ['linux', 'tizen']:
        stacktest_env.ParseConfig('pkg-config --cflags --libs sqlite3')
    elif target_os in ['msys_nt', 'windows']:
        stacktest_env.PrependUnique(LIBS=['sqlite3'])

if target_os not in ['msys_nt', 'windows']:
    stacktest_env.PrependUnique(LIBS=['m'])

    if target_os in ['tizen', 'linux']:
        stacktest_env.ParseConfig("pkg-config --cflags --libs gobject-2.0 gio-2.0 glib-2.0")

######################################################################
# Source files and Targets
######################################################################
unittests = []
unittests += stacktest_env.Program('stacktests', ['stacktests.cpp'])
unittests += stacktest_env.Program('cbortests', ['cbortests.cpp'])

Alias("test", unittests)

stacktest_env.AppendTarget('test')
if stacktest_env.get('TEST') == '1':
    if target_os in ['linux', 'windows']:
        run_test(stacktest_env,
                 'resource_csdk_stack_test_stacktests.memcheck',
                 'resource/csdk/stack/test/stacktests')
        run_test(stacktest_env,
                 'resource_csdk_stack_test_cbortests.memcheck',
                 'resource/csdk/stack/test/cbortests')

stacktest_env.UserInstallTargetExtra(unittests, 'tests/resource/csdk/stack/')

